package interfaceGrafica;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

import topologia.Link;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

public class Acoes extends JFrame {
	protected static mxGraph graph = new mxGraph();
	protected static HashMap<String, Object> m = new HashMap<String, Object>();
	static HashMap<String, HashMap<String, Link>> topologia = new HashMap<String, HashMap<String,Link>>();
	static HashMap<String, String> posicaoNos = new HashMap<String, String>();
	private mxGraphComponent graphComponent;
	private JTextField texto;
	private JButton botaoAdd;
	private JButton botaoDel;
	private JButton botaoLigar;
	private JButton botaoSimular;
	private Object cell;
	
	public static HashMap getM() {
		return m;
	}
	
	public static mxGraph getGraph() {
		return graph;
	}
	
	public Acoes() {
		super("SNETS");
		initGUI();
	}
	
	private void initGUI() {
		setSize (800, 600);
		setLocationRelativeTo(null);
		
		texto = new JTextField();
		getContentPane().add(texto);
		texto.setPreferredSize(new Dimension(400, 21));
		setLayout(new FlowLayout(FlowLayout.LEFT));
		
		botaoAdd = new JButton("Adicionar");
		getContentPane().add(botaoAdd);
		botaoAdd.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				AdicionarGrafo add = new AdicionarGrafo(texto.getText());
				
			}
		});
		
		botaoDel = new JButton("Deletar");
		getContentPane().add(botaoDel);
		botaoDel.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				graph.getModel().remove(cell);
			}
		});
		
		botaoLigar = new JButton("Ligar");
		getContentPane().add(botaoLigar);
		botaoLigar.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				AdicionarLinha linha = new AdicionarLinha();
			}
		});
		
		botaoLigar = new JButton("Simular");
		getContentPane().add(botaoSimular);
		botaoSimular.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				AdicionarLinha linha = new AdicionarLinha();
			}
		});
		
		graphComponent = new mxGraphComponent(graph);
		graphComponent.setPreferredSize(new Dimension(770, 480));
		getContentPane().add(graphComponent);
		
		graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
			public void mouseReleased (MouseEvent e){
				cell = graphComponent.getCellAt(e.getX(),  e.getY());
				System.out.println(e.getX());
			}
		
		});
		
		
	}
}
